/**
 * @file Assignment_D.cpp
 * @brief 
 * @author htli (3180102114@zju.edu.cn)
 * @version 1.0
 * @date 2021-10-03
 * 
 * @copyright Copyright (c) 2021  linhuo2020
 * 
 */
#include "SecantSolver.h"
double f1(const double x)
{
    return sin(x / 2.0) - 1;
};
double f2(const double x)
{
    return exp(x) - tan(x);
};
double f3(const double x)
{
    return x * x * x - 12 * x * x + 3 * x + 1;
};
void display(const double x0, const double x1)
{
    std::cout << "Take initial values as " << x0 << ", " << x1 << ":" << std::endl;
};

int main()
{
    SecantSolver A;
    A.set_max_iteration(500);
    A.set_tolerance(1e-8);

    std::cout << "D.1" << std::endl;
    A.set_pf(f1);
    A.set_init(0, M_PI / 2.0);
    display(0, M_PI / 2.0);
    A.solve();
    display(-5 * M_PI / 2.0, -2 * M_PI);
    A.set_init(-5 * M_PI / 2.0, -2 * M_PI);
    A.solve();

    std::cout << "D.2" << std::endl;
    A.set_pf(f2);
    A.set_init(1, 1.4);
    display(1, 1.4);
    A.solve();
    A.set_init(-3.5, -1);
    display(-3.5, -1);
    A.solve();

    std::cout << "D.3" << std::endl;
    A.set_pf(f3);
    A.set_init(0, -1.5);
    display(0, -1.5);
    A.solve();
    A.set_init(10, 20);
    display(10, 20);
    A.solve();
};